$(document).ready(function(){
	initArticle();
	
});



//定义当前页数

var articleCurrentIndex;

function getArticle(index){
	var url = "/HyperIT/article/getArticle";
	var parm = "size=10&indexPageNum="+index+"&status=1";
	$.get(url,parm,function(data){
		if(data.serviceResult){
			console.log(data);
			var articleList = data.resultParm.article_user;
			showArticle(articleList);
			articleCurrentIndex++;
		}else{
			alert(data.resultInfo);
		}
	});
}

function showArticle(articleList){
	var str = '';
	for(var i = 0; i<articleList.length; i++){
		str+='<tr id="article_'+articleList[i].article.id+'"><td>'+articleList[i].userdetail.name+'</td>';
		str+='<td>'+articleList[i].article.title+'</td>';
		str+='<td>'+articleList[i].article.createtime.split(" ")[0]+'</td>';
		str+='<td><a href="blogDetail.html?userDetail_id='+articleList[i].article.userDetail_id+'&id='+articleList[i].article.id+'"><button>详 情</button></a><button onclick="delArticle(this)">删 除</button></td></tr>';
	}
	$("#allBlog").append(str);
}

function getMoreArticle(){
	getArticle(articleCurrentIndex);
}

function initArticle(){
	articleCurrentIndex = 1;
	getArticle(articleCurrentIndex);
}

function delArticle(which){
	var $thisArticle;
	$thisArticle = $(which).parent().parent();
	var id = $thisArticle.attr("id").split("_")[1];
	var msg = "确定要删除该文章吗？";
		if (confirm(msg)==true){
			var url = "/HyperIT/article/deleteArticle";
			var parm = "article_id="+id;
			$.get(url,parm,function(data){
				if(data.serviceResult){
					$thisArticle.remove();
					alert(data.resultInfo);
				}
				else{
					alert(data.resultInfo);
				}
			});
		}
		else{
		return false;
	}
}
